翻訳と辞書
Words near each other
・ Fragrant, Kentucky
・ Fragum
・ Fragum erugatum
・ Fragum fragum
・ Fragum unedo
・ Fraham
・ Frahang-i Oim-evak
・ Frahang-i Pahlavig
・ Frahelž
・ Fraher Field
・ Frahier-et-Chatebier
・ Frahm
・ Fraiburgo
・ Fraidy Cat
・ Fragile Allegiance
Fragile base class
・ Fragile binary interface problem
・ Fragile Bird
・ Fragile Equality
・ Fragile Eternity
・ Fragile Families and Child Wellbeing Study
・ Fragile Figures
・ Fragile Future
・ Fragile Heart
・ Fragile Machine
・ Fragile matter
・ Fragile mental retardation 2
・ Fragile Records
・ Fragile state
・ Fragile States Index


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Fragile base class : ウィキペディア英語版
Fragile base class

The fragile base class problem is a fundamental architectural problem of object-oriented programming systems where base classes (superclasses) are considered "fragile" because seemingly safe modifications to a base class, when inherited by the derived classes, may cause the derived classes to malfunction. The programmer cannot determine whether a base class change is safe simply by examining in isolation the methods of the base class.
One possible solution is to make instance variables private to their defining class and force subclasses to use accessors to modify superclass states. A language could also make it so that subclasses can control which inherited methods are exposed publicly. These changes prevent subclasses from relying on implementation details of superclasses and allow subclasses to expose only those superclass methods that are applicable to themselves.
Another alternative solution could be to have an interface instead of superclass.
The fragile base class problem has been blamed on open recursion (dynamic dispatch of methods on this), with the suggestion that invoking methods on this default to closed recursion (static dispatch, early binding) rather than open recursion (dynamic dispatch, late binding), only using open recursion when it is specifically requested; external calls (not using this) would be dynamically dispatched as usual.〔"(Selective Open Recursion: A Solution to the Fragile Base Class Problem )", Jonathan Aldrich〕〔"(Selective Open Recursion: A Solution to the Fragile Base Class Problem )", ''(Lambda the Ultimate )''〕
==Java example==
The following trivial example is written in the Java programming language and shows how a seemingly safe modification of a base class, can cause an inheriting subclass to malfunction by entering an infinite recursion which will result in a stack overflow.

class Super
}
class Sub extends Super

Calling the dynamically bound method ''inc2()'' on an instance of ''Sub'' will correctly increase the field ''counter'' by one. If however the code of the superclass is changed in the following way:

class Super
}

a call to the dynamically bound method ''inc2()'' on an instance of ''Sub'' will cause an infinite recursion between itself and the method ''inc1()'' of the sub-class and eventually cause a stack overflow. This problem could have been avoided, by declaring the methods in the superclass as final, which would make it impossible for a sub-class to override them. However, this is not always desirable or possible. Therefore, it is good practice for super-classes to avoid changing calls to dynamically-bound methods.

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Fragile base class」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.